#ifndef	_MIN_LENGTH_SUBS_H_
#define	_MIN_LENGTH_SUBS_H_

#include <map>
#include "types.h"
///#include "DynamicBitset.h"
//#include <pair>
#include <strings.h> /* For bzero */
#include <vector>


#include <iostream>
using namespace std;

/*
 * This class holds all the substrings of the reference sequence, of a given length.
 * Each substring will hold all the positions where it appears in the reference sequence.
 * The class also includes the indicators for each input-file and input-sequence in a file, if that sequence was processed or not
 * (updating is doen atomically).
 * Assumptions: This implementations assumes that the maximal length is 32 chars and that the machine is 64-bit machine.
 */
class MinLengthSubs
{
  public:
	typedef ulong SubStr;

  private:
	struct MultiMapValues
	{
		SubStr sub;
		vector<uint> *positions;

		MultiMapValues(SubStr _sub, vector<uint> *_positions) :
			sub(_sub),
			positions(_positions)
		{
		}


	};

	//typedef pair<SubStr, DynamicBitset*> MultiMapValues;
	typedef pair<SubStr, MultiMapValues> MultiMapElement;
	typedef multimap<SubStr, MultiMapValues> MultiMap;

	///size_t sub_len;  -- unnecessary anymore
	size_t ref_len;
	MultiMap *subs_map;
	

	/* Retrieves the DynamicBitset of the given substring.
	 * If the substring isn't found, returns NULL.
	 */
	vector<uint> *innerGetSubstringPositions(SubStr sub);

  public:
	/* C'tor:
	 */
	MinLengthSubs();

	~MinLengthSubs();

	void addSubstring(SubStr sub, size_t pos);

	/* Retrieves the positions of the given substring.
	 * If the substring isn't found, returns NULL.
	 */
	const vector<uint> *getSubstringPositions(SubStr sub) const;

#ifdef DEBUG
	void print() const;
#endif /* DEBUG */
};

#endif	/* _MIN_LENGTH_SUBS_H_ */

